<script setup lang="ts">
import { ref, defineOptions } from 'vue'
import { sendMoney } from '@/api/getAxios2'
import { user } from '@/store/storeName'
import { showToast } from 'vant';
const props = defineProps(['name', 'text', 'img'])
const store = user();
/**
 * 充钱行为
 */
const toSendMoney = () => {
    if (!store.token) {
        showToast("暂未登录")
    } else {
        sendMoney(store.token).then((res: any) => {
            if (res.data !== "登录失败!") {
                store.sendMoney(res.data * 1)
                showToast("充值30火星币成功")
            }
        })
    }
}

</script>
<template>
    <div id="card">
        <img :src="img" alt="" class="left">
        <div class="right" v-if="name === '设置'" @click="$router.push('/setting')">
            <div class="name">{{ name }}<span class="text">
                    <span v-if="name === '我的账户'">{{ store.user.money }}</span>
                    <span v-if="name === '我的等级'">{{ `还差${store.getLevels()}经验才能升级` }}</span>
                    {{ text }}</span>
            </div>
            <div v-if="name === '我的账户'" class="sendMoney" @click="toSendMoney">充值</div>
            <img v-else src="@/assets/Person/book_shalfxiaojiantou.png" alt="" class="go">
        </div>
        <div class="right" v-else-if="name === '我的收藏'" @click="$router.push('/Like')">
            <div class="name">{{ name }}<span class="text">
                    <span v-if="name === '我的账户'">{{ store.user.money }}</span>
                    <span v-if="name === '我的等级'">{{ `还差${store.getLevels()}经验才能升级` }}</span>
                    {{ text }}</span>
            </div>
            <div v-if="name === '我的账户'" class="sendMoney" @click="toSendMoney">充值</div>
            <img v-else src="@/assets/Person/book_shalfxiaojiantou.png" alt="" class="go">
        </div>
        <div class="right" v-else>
            <div class="name">{{ name }}<span class="text">
                    <span v-if="name === '我的账户'">{{ store.user.money }}</span>
                    <span v-if="name === '我的等级'">{{ `还差${store.getLevels()}经验才能升级` }}</span>
                    {{ text }}</span>
            </div>
            <div v-if="name === '我的账户'" class="sendMoney" @click="toSendMoney">充值</div>
            <img v-else src="@/assets/Person/book_shalfxiaojiantou.png" alt="" class="go">
        </div>
    </div>
</template>

<style scoped lang='less'>
#card {
    width: 100%;
    padding: 0 5vw;
    box-sizing: border-box;
    background-color: white;
    display: flex;
    align-items: center;
    padding-top: 5vw;

    .left {
        width: 1.625rem;
        // height: 8vw;
        display: block;
        margin-right: 1rem;
        position: relative;
        top: -2vw;
    }

    .right {
        width: 100%;
        padding-bottom: 5vw;
        border-bottom: 1px solid #eee;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .name {
            // margin-right: 1.25rem;
            display: flex;
            align-items: center;

            .text {
                margin-left: 1rem;
                color: #dac584;
                font-size: .875rem;
            }
        }

        .go {
            width: .375rem;
            display: block;
        }
    }
}

.sendMoney {
    padding: 1.5vw 5vw;
    background-color: #d9646f;
    color: white;
    border-radius: 20px;
    font-size: .875rem;
}
</style>